import QtQuick 2.0
import QtQuick.Controls 2.5
import QtQuick.Layouts 1.12

Item {
    width: 850
    height: 580

    Rectangle
    {
        id:p4h_toobarHeader
        height: 40
        width:parent.width
        radius: height/2
        color: "#883080a0"

        Label {
            id:label_date
            text: qsTr("日期")
            anchors.left: parent.left
            anchors.right: ats.left
            font.bold: true
            font.family: "Tahoma"
            font.pixelSize: 17*main_screen.minSize
            color: "#40ffff"
            anchors.verticalCenter: parent.verticalCenter
            elide: Label.ElideRight
            horizontalAlignment: Qt.AlignHCenter
            verticalAlignment: Qt.AlignVCenter
        }
        ToolSeparator {
            id:ats
            x:parent.width*0.20
            height: parent.height
            MouseArea{
                height: parent.height
                anchors.leftMargin: -width/2+parent.width/2
                width: 50
                anchors.left: parent.left
                acceptedButtons: Qt.LeftButton //只处理鼠标左键
                onPositionChanged: {
                    parent.x = mouseX+parent.x-width/2
                }
            }
        }
        Label {
            id:label_time
            text: qsTr("时间")
            anchors.left: ats.right
            anchors.right: bts.left
            font.bold: true
            font.family: "Tahoma"
            font.pixelSize: 17*main_screen.minSize
            color: "#40ffff"
            anchors.verticalCenter: parent.verticalCenter
            elide: Label.ElideRight
            horizontalAlignment: Qt.AlignHCenter
            verticalAlignment: Qt.AlignVCenter
        }
        ToolSeparator {
            id:bts
            x:parent.width*0.40
            height: parent.height
            MouseArea{
                height: parent.height
                anchors.leftMargin: -width/2+parent.width/2
                width: 50
                anchors.left: parent.left
                acceptedButtons: Qt.LeftButton //只处理鼠标左键
                onPositionChanged: {
                    parent.x = mouseX+parent.x-width/2
                }
            }
        }
        Label {
            id:label_text
            text: qsTr("报警文本")
            anchors.left: bts.right
            anchors.right: parent.right
            font.bold: true
            font.family: "Tahoma"
            font.pixelSize: 17*main_screen.minSize
            color: "#40ffff"
            anchors.verticalCenter: parent.verticalCenter
            elide: Label.ElideRight
            horizontalAlignment: Qt.AlignHCenter
            verticalAlignment: Qt.AlignVCenter
        }

    }
    Rectangle
    {
        id:p4h_toobarBotton
        radius: height/2
        color: "#883080a0"
        height: 40
        width: parent.width
        anchors.bottom: parent.bottom
        Label {
            text: qsTr("历史记录")
            font.bold: true
            font.family: "Tahoma"
            font.pixelSize: 17*main_screen.minSize
            color: "#40ffff"
            anchors.verticalCenter: parent.verticalCenter
            width: parent.width
            elide: Label.ElideRight
            horizontalAlignment: Qt.AlignHCenter
            verticalAlignment: Qt.AlignVCenter
        }
    }

    ListView {
        id: p4h_listView
        clip: true
        width: parent.width
        anchors.top: p4h_toobarHeader.bottom
        snapMode: ListView.SnapToItem
        orientation:ListView.Vertical
//        anchors.fill: parent
        anchors.bottom: p4h_toobarBotton.top

        ScrollBar.vertical: ScrollBar {
            width: 25
            active: true
            anchors.right: parent.right
            parent: parent
        }

        model:ListModel{
            id:p4h_listView_model
        }
        delegate:
            Item {
            id: wrapper
            width: parent.width
            height: 30

            EXC_listViewItemDelegate3{
                id: p4h_listViewItemdeleg_data
                height: 30
                locationBase: label_date
                mtext: text_date
                mcolor: textColor
                textFontpixelSize: 21*main_screen.minSize
            }

            EXC_listViewItemDelegate3{
                id: p4h_listViewItemdeleg_time
                height: 30
                locationBase: label_time
                mtext: text_time
                mcolor: textColor
                textFontpixelSize: 21*main_screen.minSize
            }
            EXC_listViewItemDelegate3{
                id: p4h_listViewItemdeleg_text
                height: 30
                locationBase: label_text
                mtext: text_represent
                mcolor: textColor
                textFontpixelSize: 21*main_screen.minSize
            }

            MouseArea {
                id:mouseAreaThis
                anchors.fill: parent
                onClicked: p4h_listView.currentIndex = index
                Rectangle{
                    anchors.fill: parent
                    border.width:1
                    border.color:wrapper.ListView.isCurrentItem?"lightskyblue":"transparent"
                    color:"transparent"
                }
            }
        }
    }
//    Component.onCompleted: {
//        addModel("1","2","3")
//    }
    function addModel(data, time, represent)
    {
        p4h_listView_model.insert(0,
                                  {
                                      "textColor":"#ffffff",
                                      "text_date":data,
                                      "text_time":time,
                                      "text_represent":represent
                                  })
    }
    function addModelRed(data, time, represent)
    {
        p4h_listView_model.insert(0,
                                  {
                                      "textColor":"#dc4e4e",
                                      "text_date":data,
                                      "text_time":time,
                                      "text_represent":represent
                                  })
    }
    function addModelGreen(date, time, represent)
    {
        p4h_listView_model.insert(0,
                                  {
                                      "textColor":"#58dad3",
                                      "text_date":date,
                                      "text_time":time,
                                      "text_represent":represent
                                  })
    }
    function addModelWithColor(color,data, time, represent)
    {
        p4h_listView_model.insert(0,
                                  {
                                      "textColor":color,
                                      "text_data":data,
                                      "text_time":time,
                                      "text_represent":represent
                                  })
    }
    function clearModel()
    {
        p4h_listView_model.clear()
    }
}

/*##^##
Designer {
    D{i:0;formeditorZoom:0.75}
}
##^##*/
